// packageOrder/pages/complaint/complaint.js
import MessageService from '../../../service/MessageService.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId: '',
    factory: '',
    type: 0,
    content: '',
    fileList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const { id, factoryId, type } = options;
    this.messageService = new MessageService();
    this.setData({orderId: id, factoryId, type})
    if(type == 1){
      wx.setNavigationBarTitle({
        title: '申请售后'
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  onImagesChange: function (e) {
    const images = e.detail.images;
    const fileList = images.map(item => {
      return { fileUrl: item };
    })
    this.setData({ fileList: fileList })
  },
  onContentChange: function (e) {
    this.setData({ content: e.detail.value });
  },
  submit: function (e) {
    const { orderId, factoryId, content,type, fileList } = this.data;
    if (!orderId) {
      return;
    }
    if (!factoryId) {
      return;
    }
    if (!content) {
      return;
    }
    const param = { orderId, content, type, complainUser: factoryId, fileList}
    this.messageService.complaint(param).then(function (res) {
      if (res.status == 0) {
        wx.navigateBack()
      }
    })
  }
})